package geektime.spring.cn.databasespring;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

@SpringBootApplication
@Slf4j
public class DatabaseSpringApplication implements CommandLineRunner {
	@Autowired
	private DataSource dataSource;
	@Override
	public void run(String... args) throws Exception {
		shouconnection();
	}
	private void shouconnection() throws SQLException {
		log.error(dataSource.toString());
		Connection connection = dataSource.getConnection();
		log.error(connection.toString());
		connection.close();
	}

	public static void main(String[] args) {
		SpringApplication.run(DatabaseSpringApplication.class, args);
	}

}
